
<script>
/* eslint-disable */

import Node from "./Node";

export default {
  name: "Spine",

  mixins: [Node],

  props: {
    spineProps:{type:Object,default:()=>{return {}}},
  },
  
  watch: {
    nodeProps: {
      handler(newv, oldv) {
        // console.log("sprite watch nodeProps",newv,oldv);
        let oldProps = this.curProps;
        this.curProps = this.mergeProps();
        this._updateNodeProps(this.ccnode, oldProps, this.curProps);
      },
    },
    nodeComps: {
      handler(newv, oldv) {
        // console.log("sprite watch nodeComps",newv,oldv);
        let oldComps = this.curComps;
        this.curComps = this.mergeComps();
        this._updateNodeComps(this.ccnode, oldComps, this.curComps);
      },
    },
    spineProps:{
      handler(newv,oldv){
        // console.log("sprite watch spriteProps",newv,oldv);
        let oldComps = this.curComps;
        this.curComps = this.mergeComps(this.nodeComps,newv);
        this._updateNodeComps(this.ccnode,oldComps,this.curComps);
      }
    },
  },

  created() {
    // console.log("particle created",this.dict,this.playcount);
    this.createSpine();
  },

  methods: {
    getSkeleton() {
        return this.ccnode.getComponent(sp.Skeleton);
    },
    //////////////////////////
    // 下面函数替换Node
    createNode() {},
    updateNodeProps(node, oldp, newp) {},
    updateNodeComps(node, oldp, newp) {},

    //////////////////////////
    mergeProps() {
      return this.nodeProps;
    },
    mergeComps() {
      let comps = [
        {
          type: sp.Skeleton,
          props: {
              skeletonData: null,
              defaultSkin: '',
              defaultAnimation: '',
              animation: '',
              loop: true,
              premultipliedAlpha: true,
              timeScale: 1,
              debugSlots: false,
              debugBones: false,
              useTint:false,
              enableBatch:false,
              ...this.spineProps,
              //cacheMode
          },
        },
      ];
      if (this.nodeComps) {
        this.nodeComps.forEach((c) => {
          if (c && c.type && c.type !== sp.Skeleton ) {
            comps.push(c);
          }
        });
      }
      return comps;
    },
    createSpine() {
      if (!this.ccnode) {
        this.curComps = this.mergeComps();
        this.curProps = this.mergeProps();
        this._createNode(this.curProps, this.curComps);
      }
    },
  },
};
</script>
